#ifndef I_WS_MODULE_H
#define I_WS_MODULE_H

#include <iostream>
#include <iosfwd>
#include "GUID.h"
#include "IModule.h"
#include "ILogModule.h"
#include "IPluginManager.h"
#include "PluginModule/INet.h"
#ifdef _MSC_VER
#pragma warning(disable: 4244 4267)
#endif


namespace FragrantGrass
{
	class IWSModule : public IModule
	{
		DECLARE_MODULE_NAME(IWSModule)
	public:

		template<typename BaseType>
		bool AddReceiveCallBack(const int nMsgID, BaseType* pBase, void (BaseType::* handleRecieve)(const SOCK, const int, const char*, const uint32_t))
		{
			NET_MESSAGE_HANDLER_FUNCTOR functor = std::bind(handleRecieve, pBase, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
			NET_MESSAGE_HANDLER_FUNCTOR_PTR functorPtr(new NET_MESSAGE_HANDLER_FUNCTOR(functor));

			return AddReceiveCallBack(nMsgID, functorPtr);
		}

		template<typename BaseType>
		bool AddReceiveCallBack(BaseType* pBase, void (BaseType::* handleRecieve)(const SOCK, const int, const char*, const uint32_t))
		{
			NET_MESSAGE_HANDLER_FUNCTOR functor = std::bind(handleRecieve, pBase, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4);
			NET_MESSAGE_HANDLER_FUNCTOR_PTR functorPtr(new NET_MESSAGE_HANDLER_FUNCTOR(functor));

			return AddReceiveCallBack(functorPtr);
		}

		template<typename BaseType>
		bool AddEventCallBack(BaseType* pBase, void (BaseType::* handler)(const SOCK, const FG_NET_EVENT, INet*))
		{
			NET_EVENT_HANDLER_FUNCTOR functor = std::bind(handler, pBase, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
			NET_EVENT_HANDLER_FUNCTOR_PTR functorPtr(new NET_EVENT_HANDLER_FUNCTOR(functor));

			return AddEventCallBack(functorPtr);
		}

		//as client
		virtual void Initialization(const char* strIP, const unsigned short nPort) = 0;

		//as server
		virtual int Initialization(const unsigned int nMaxClient, const unsigned short nPort, const int nCpuCount = 4) = 0;
		virtual int ExpandBufferSize(const unsigned int size = 1024 * 1024 * 20) = 0;

		virtual void RemoveReceiveCallBack(const int nMsgID) = 0;

		virtual bool AddReceiveCallBack(const int nMsgID, const NET_MESSAGE_HANDLER_FUNCTOR_PTR& cb) = 0;

		virtual bool AddReceiveCallBack(const NET_MESSAGE_HANDLER_FUNCTOR_PTR& cb) = 0;

		virtual bool AddEventCallBack(const NET_EVENT_HANDLER_FUNCTOR_PTR& cb) = 0;

		virtual bool Execute() = 0;


		virtual bool SendMsg(const std::string& msg, const SOCK nSockIndex, const bool text = true) = 0;
		virtual bool SendMsgToAllClient(const std::string& msg, const bool text = true) = 0;

		virtual INet* GetNet() = 0;
	};
}

#endif
